<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H+ 后台主题UI框架 - Bootstrap Table</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="/admin/favicon.ico"> <link href="/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/admin/css/animate.css" rel="stylesheet">
    <link href="/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="/admin/js/jquery.min.js?v=2.1.4"></script>
    <style>
        a{
            color:#777;
        }
    </style>

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <!-- Example Events -->
                    <div class="example-wrap">
                        <div class="example">
                            <div class="btn-group hidden-xs" id="tabtar" role="group">
                                <button type="button" class="btn btn-primary" onclick="add()">
                                    <i class="glyphicon glyphicon-plus" aria-hidden="true"></i> 添加
                                </button>
                                <button id='dels' type="button" class="btn btn-warning">
                                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i> 批量删除
                                </button>
                            </div>
                            <table data-toggle="table" id="table"> 
                                <thead>
                                    <tr>
                                        <th data-field="state" data-checkbox="true"></th>
                                        <th data-field="id" data-sortable='true'>ID</th>
                                        <th data-field="username">登录名</th>
                                        <th data-field="tel">手机</th>
                                        <th data-field="email">邮箱</th>
                                        <th data-field="role">角色</th>
                                        <!-- <th data-field="created_at">加入时间</th> -->
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($arr as $list)
                                    <tr>
                                        <td></td>
                                        <td>{{$list->id}}</td>
                                        <td>{{$list->username}}</td>
                                        <td>{{$list->tel}}</td>
                                        <td>{{$list->email}}</td>
                                        <td>{{$list->role}}</td>
                                        <!-- <td>{{$list->created_at}}</td> -->
                                        <td>
                                            <div class="switch">
                                                <div class="onoffswitch">
                                                    <input type="checkbox" @if($list->state==1)checked @endif class="onoffswitch-checkbox" id="bt{{$list->id}}">
                                                    <label class="onoffswitch-label" for="bt{{$list->id}}"  onclick="changeState({{$list->id}},this)">
                                                        <span class="onoffswitch-inner"></span>
                                                        <span class="onoffswitch-switch"></span>
                                                    </label>
                                                </div>
                                            </div>
                                        </td>
                                        <td>
                                            <a href="javascript:;" class='glyphicon glyphicon-pencil edit' onclick="edit(this,{{$list->id}})" title='修改'></a>
                                            <a href="javascript:;" class='glyphicon glyphicon-trash del' onclick="del({{$list->id}},'{{$list->role}}')" title='删除'></a>
                                        </td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- End Example Events -->
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="/admin/js/layer.js"></script>

    <!-- 自定义js -->
    <script src="/admin/js/content.js?v=1.0.0"></script>


    <!-- Bootstrap table -->
    <script src="/admin/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="/admin/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="/admin/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <!-- jQuery Validation plugin javascript-->
    <!-- <script src='/admin/js/plugins/validate/jquery.validate.min.js'></script>
    <script src='/admin/js/plugins/validate/messages_zh.min.js'></script>

    <script src='/admin/js/demo/form-validate-demo.js'></script> -->
    <script src="/laydate/laydate.js"></script>

    <!-- Peity -->
    <!-- <script src="/admin/js/demo/bootstrap-table-demo.js"></script> -->
    <script src="/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="/admin/js/plugins/peity/jquery.peity.min.js"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
    <!--统计代码，可删除-->
    <script>
        // 删除函数
        function del(ids,roles){
            if("{{$userrole}}"=='普通管理员'){
                layer.msg('你没有权限这么做');
                return;
            }
            if(typeof roles=='object'){
                for(role of roles){
                    if(role=='超级管理员'){
                        layer.msg('你不能删除超级管理员');
                        return;
                    }
                }
            }else{
                if(roles=='超级管理员'){
                    layer.msg('你不能删除超级管理员');
                    return;
                }
            }
            
            if(typeof ids!='object' & ids!='none'){
                arr=new Array();
                arr[0]=ids.toString(); // 将数字转为数组
                ids=arr;
            }
            if (ids!=='none') {
                layer.confirm('你确定要删除吗？', {
                    btn: ['删除','取消']
                }, function(){
                    // ajax传输数据并响应
                    $.post("/admin/bkuser/bkuser_del",{"_method":"DELETE","ids":ids},function(data){
                        if (data == 1) {
                            layer.msg('删除成功', {icon: 1});
                            //删除bt表格中的选中行
                            $('#table').bootstrapTable('remove', {
                                field: 'id',
                                values: ids 
                            });
                        }else{
                            layer.msg('删除失败',{icon: 2});
                        }
                    }).done(function(){
                        $('#table').bootstrapTable('uncheckAll');// 取消选中所有行
                    })
                }, function(){
                    layer.msg('已取消',{icon: 2});
                    $('#table').bootstrapTable('uncheckAll');
                });
            }else{
                layer.msg('未选择数据');
            }
        }
        //删除
        $('#dels').click(function(){
            var idarr=$.map($('#table').bootstrapTable('getSelections'), function (row){
                return row.id;
            }); //获取选中行(数组)
            var rolearr=$.map($('#table').bootstrapTable('getSelections'), function (row){
                return row.role;
            });
            var ids = $('#table').bootstrapTable('getSelections')[0]?idarr:'none';
            // 调用删除函数
            del(ids,rolearr);
        });
        // 修改
        function edit(thiss,id){
            if("{{$userrole}}"=='普通管理员'){
                layer.msg('你没有权限这么做');
                return;
            }
            var nrow=$(thiss).parent().parent().index();  //当前行下标
            $('#table').bootstrapTable('check',nrow);  //选中当前行
            var olddata=$('#table').bootstrapTable('getSelections')[0];//当前行信息
            // 打开修改页
            layer.open({
                type: 2,
                title: '修改信息',
                skin: 'layui-layer-demo', //样式类名
                // closeBtn: false, //不显示关闭按钮
                // scrollbar: false, //屏蔽滚动
                area: ['600px', '550px'],
                anim: 0,
                shadeClose: true, //开启遮罩关闭
                content:"/admin/bkuser/bkuser_edit?id="+id+"&nrow="+nrow,
                // success:
                cancel:function(){  
                    layer.msg('已取消修改');
                },
                end:function(){
                    $('#table').bootstrapTable('uncheckAll');// 取消选中所有行
                }
            });
        }

        // 添加
        function add(){
            if("{{$userrole}}"=='普通管理员'){
                layer.msg('你没有权限这么做');
                return;
            }
            var index=layer.open({
                type: 2,
                title: '添加管理员',
                // maxmin: true, //最大小化
                shadeClose: true, //点击遮罩关闭层
                area : ['800px' , '500px'],
                content: '/admin/bkuser/bkuser_add',
                cancel:function(){
                    layer.msg('取消添加',{'icon':2});
                }
            });
        }
    </script>
    <script>
        function changeState(id,thiss){
            if("{{$userrole}}"=='普通管理员'){
                layer.msg('你没有权限这么做');
                if($(thiss).siblings('input').prop('checked')){
                    $(thiss).siblings('input').prop('checked',false);
                }else{
                    $(thiss).siblings('input').prop('checked',true);
                }
                return;
            }
            $.post('/admin/bkuser/bkuser_update',{'id':id,'state':'1'},function(data){
                if(data==1){
                    layer.msg('已启用');
                }else{
                    layer.msg('已禁用');
                }
            }).fail(function(){
                layer.msg('出错了');
            })
        }
    </script>
    <script>
        // bt表格样式
        $('#table').bootstrapTable({
            search:true,
            showRefresh:true,
            showColumns:true,
            showToggle:true,
            pagination:true,
            cache:false,
            pageSize:'5',
            iconSize:'outline',
            toolbar: '#tabtar',
        });
        // 刷新功能
        // $('#table').bootstrapTable('refresh',{url:'/'});
    </script>

</body>

</html>
